package com.c.yinyuezhushou.Entity;

import android.content.SharedPreferences;
import android.os.Build;

import com.c.yinyuezhushou.MyApplication;

import static android.content.Context.MODE_PRIVATE;

public class SetupEntity {
    private SharedPreferences.Editor editor;
    private String path;
    private int playbr;
    private int downbr;
    private boolean isDownAsk;

    public SetupEntity(MyApplication myApplication){
        SharedPreferences sharedPreferences = myApplication.getSharedPreferences("setup",MODE_PRIVATE);
        editor = sharedPreferences.edit();
        playbr = sharedPreferences.getInt("playbr",128000);
        downbr = sharedPreferences.getInt("downbr",998000);
        isDownAsk = sharedPreferences.getBoolean("isdownask",true);

        int v = Build.VERSION.SDK_INT;
        if (v>20&&v<30){
            path = sharedPreferences.getString("path","/sdcard/音月/");
        }else {
            path = sharedPreferences.getString("path","/sdcard/Music/月光/");
        }
    }

    public boolean isDownAsk() {
        return isDownAsk;
    }

    public void setDownAsk(boolean downAsk) {
        isDownAsk = downAsk;
        editor.putBoolean("iddownask",downAsk);
        editor.apply();
    }

    public int getPlaybr() {
        return playbr;
    }

    public void setPlaybr(int playbr) {
        this.playbr = playbr;
        editor.putInt("playbr",playbr);
        editor.apply();
    }

    public int getDownbr() {
        return downbr;
    }

    public void setDownbr(int downbr) {
        this.downbr = downbr;
        editor.putInt("downbr",downbr);
        editor.apply();
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
        editor.putString("path",path);
        editor.apply();
    }

    public  int getIntBr(int index){
        switch (index){
            case 0:
                return 128000;
            case 1:
                return 192000;
            case 2:
                return 320000;
            case 3:
                return 998000;
        }
        return 128000;
    }

    public int getIntIndex(int br){
        switch (br){
            case 128000:
                return 0;
            case 192000:
                return 1;
            case 320000:
                return 2;
            case 998000:
                return 3;
        }
        return 0;
    }
}
